﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using express;
using express.bttree;
using express.compiler;

namespace express_test
{

    public class Program
    {
        public class TestOpNode : OpNode
        {
            private static Dictionary<string, Command> methods =
                new Dictionary<string, Command>();

            static TestOpNode()
            {
                methods.Add("getlevel", (a, b) => {
                    return 11;
                });

                methods.Add("getname", (ctx, args) =>
                {
                    string arg = args.GetParamAsString(1);
                    return "chenhonghong";
                });
            }

            protected override Dictionary<string, Command> GetCommands()
            {
                return methods;
            }
        }
        public static void Main(string[] args)
        {
            string expr = "getlevel(2)>=11&&getname(名字)==chenhonghong";
            var node = ExprUtils.convert(expr, typeof(TestOpNode));
            Context context = new Context();
            var result = node.execute(context);
            Console.WriteLine("最终比较结果:" + result);
            Console.WriteLine(context.getResultAtIndex(1));
        }
    }
}
